﻿namespace UnityEditor
{
    using System;
    using System.Collections;
    using UnityEngine;

    internal class AnimationCleanupPopup : EditorWindow
    {
        private GameObject m_AnimatedObject;
        private AnimationClip m_Clip;
        private AnimationWindow m_Host;
        private Hashtable m_LeftoverCurves = new Hashtable();
        private Vector2 m_ScrollValue = Vector2.zero;

        private void DeleteLeftoverCurves()
        {
            IEnumerator enumerator = this.m_LeftoverCurves.Values.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    AnimationClipCurveData current = (AnimationClipCurveData) enumerator.Current;
                    AnimationUtility.ClearEditorCurve(this.m_Clip, current.path, current.classID, current.scriptInstanceID, current.propertyName);
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable == null)
                {
                }
                disposable.Dispose();
            }
            this.m_Host.SetDirtyPropertyList();
            this.m_Host.Repaint();
            this.m_LeftoverCurves.Clear();
            base.Repaint();
        }

        public void OnGUI()
        {
            string str;
            string str2;
            if (this.m_LeftoverCurves.Count == 0)
            {
                str = "All mis-matched curves have been deleted from the animation clip '" + this.m_Clip.name + "'.";
                str2 = string.Empty;
            }
            else
            {
                string[] textArray1 = new string[] { "The following curves in the animation clip '", this.m_Clip.name, "' are for properties that do not exist on the animated object '", this.m_AnimatedObject.name, "'." };
                str = string.Concat(textArray1);
                str2 = "Do you wish to delete these curves from the animation clip?";
            }
            GUILayout.Label(str, EditorStyles.wordWrappedLabel, new GUILayoutOption[0]);
            EditorGUILayout.BeginScrollView(this.m_ScrollValue, "OL Box");
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.ExpandWidth(true) };
            GUILayoutUtility.GetRect((float) 10f, (float) 0f, options);
            int num = (int) ((base.position.width - 30f) * 0.5f);
            int num2 = ((int) (base.position.width - 30f)) - num;
            IEnumerator enumerator = this.m_LeftoverCurves.Values.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    AnimationClipCurveData current = (AnimationClipCurveData) enumerator.Current;
                    GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                    GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.Width((float) num) };
                    GUILayout.Label(current.path + " (" + current.type.Name + ")", optionArray2);
                    GUILayoutOption[] optionArray3 = new GUILayoutOption[] { GUILayout.Width((float) num2) };
                    GUILayout.Label(current.propertyName, optionArray3);
                    GUILayout.EndHorizontal();
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable == null)
                {
                }
                disposable.Dispose();
            }
            EditorGUILayout.EndScrollView();
            GUILayout.Label(str2, EditorStyles.wordWrappedLabel, new GUILayoutOption[0]);
            bool flag = false;
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.FlexibleSpace();
            if (this.m_LeftoverCurves.Count == 0)
            {
                if (GUILayout.Button("OK", new GUILayoutOption[0]))
                {
                    flag = true;
                }
            }
            else
            {
                if (GUILayout.Button("Cancel", new GUILayoutOption[0]))
                {
                    flag = true;
                }
                if (GUILayout.Button("Delete Curves", new GUILayoutOption[0]))
                {
                    this.DeleteLeftoverCurves();
                }
            }
            GUILayout.EndHorizontal();
            if (flag)
            {
                base.Close();
            }
        }

        internal static void Show(GameObject obj, AnimationClip clip, Hashtable leftoverCurves, AnimationWindow animationWindow)
        {
            AnimationCleanupPopup window = EditorWindow.GetWindow<AnimationCleanupPopup>(true);
            window.m_AnimatedObject = obj;
            window.m_Clip = clip;
            window.m_LeftoverCurves = leftoverCurves;
            window.m_Host = animationWindow;
            window.minSize = new Vector2(400f, 300f);
            window.title = EditorGUIUtility.TextContent("UnityEditor.AnimationCleanupPopup").text;
            window.Repaint();
        }
    }
}

